#include<bits/stdc++.h>
#define ll long long
// #define lll __int128
#define lll long long
#define mod 998244353ll
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mems(a,x) memset(a,x,sizeof(a))
using namespace std;
const int maxn=400010;
const ll inf=4e17;
static char buf[1000000],*p1=buf,*p2=buf;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++
inline ll read(){ll x=0;char c=getchar();while(c<'0'||c>'9')c=getchar();while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-48;c=getchar();}return x;}
inline void write(lll x){static char buf[20];static int len=-1;if(x<0)putchar('-'),x=-x;do buf[++len]=x%10,x/=10;while(x);while(len>=0)putchar(buf[len--]+48);}
bool mbe;

int n,q;ll ss;
ll a[maxn];
ll lsh[maxn],len;
namespace sub1{
	set<ll> s;
	ll n,a[maxn],sum[maxn];
	void sovle(){
		while(q--){
			ll x=read(),ans=0;
			if(s.find(x)!=s.end())s.erase(x);
			else s.insert(x);
			n=0;for(ll i:s)a[++n]=i;
			for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i];
			if(!n){puts("0");continue;}
			int l=1,r=(n+1)/2,res=0;
			while(l<=r){
				int mid=l+r>>1;
				if(sum[mid]>=sum[n]-sum[n-mid+1])l=mid+1,res=mid;
				else r=mid-1;
			}
			// for(int i=1;i<res;i++)ans+=sum[n]-sum[n-i]-sum[i];
			// for(int i=n-res+1;i<=n;i++)ans+=sum[n]-sum[n-i]-sum[i];
			// cout<<res<<" ";
			ans+=2*res*sum[n];
			for(int i=1;i<res;i++)ans-=2*sum[i];
			for(int i=n-res+1;i<=n;i++)ans-=2*sum[i];
			if(res<=n-res)ans+=sum[n]-sum[res]-sum[res];
			printf("%lld\n",ans);
		}
	}
}
#define mid (l+r>>1)
#define ls nd<<1
#define rs nd<<1|1
int num[maxn<<2];ll tree[maxn<<2];
int p,ww;
void updata(int nd,int l,int r){
	num[nd]+=ww,tree[nd]+=lsh[p]*ww;
	if(l==r)return ;
	if(p<=mid)updata(ls,l,mid);
	else updata(rs,mid+1,r);
}
ll kthsum(int nd,int l,int r,int k){
	if(l==r)return k*lsh[l];
	if(k<=num[ls])return kthsum(ls,l,mid,k);
	else return tree[ls]+kthsum(rs,mid+1,r,k-num[ls]);
}
int query(int nd,int l,int r){
	if(r<=p)return num[nd];
	if(p<=mid)return query(ls,l,mid);
	return num[ls]+query(rs,mid+1,r);
}
#undef mid
#undef ls
#undef rs
int w[maxn],lc[maxn],rc[maxn];
lll sum[maxn];
ll val[maxn],tag[maxn];
int siz[maxn];
int rt,idx;
mt19937 rnd(time(0));
#define ls lc[u]
#define rs rc[u]
int create(ll l){
	w[++idx]=rnd()%mod,sum[idx]=val[idx]=l,siz[idx]=1;
	return idx;
}
void up(int u){
	sum[u]=sum[ls]+sum[rs]+val[u];
	siz[u]=siz[ls]+siz[rs]+1;
}
void upd(int u,ll w){
	sum[u]+=w*siz[u],val[u]+=w,tag[u]+=w;
}
void down(int u){
	if(tag[u]){
		upd(ls,tag[u]),upd(rs,tag[u]),tag[u]=0;
	}
}
int merge(int u,int v){
	if(!u||!v)return u|v;
	down(u),down(v);
	if(w[u]<w[v]){
		rs=merge(rs,v);
		up(u);return u;
	}
	else{
		lc[v]=merge(u,lc[v]);
		up(v);return v;
	}
}
pii split(int u,int k){
	if(!u)return {0,0};
	down(u);
	if(k<siz[ls]+1){
		pii t=split(ls,k);
		ls=t.se;up(u);
		return {t.fi,u};
	}
	else{
		pii t=split(rs,k-siz[ls]-1);
		rs=t.fi;up(u);
		return {u,t.se};
	}
}
int del(int u){
	down(u);
	if(ls)ls=del(ls),up(u);
	else return rs;
}
set<int> s;
void work(){
	q=read();
	// if(q<=1000)return sub1::sovle();
	for(int i=1;i<=q;i++){
		a[i]=read();lsh[++len]=a[i];
	}
	sort(lsh+1,lsh+len+1),len=unique(lsh+1,lsh+len+1)-lsh-1;
	for(int i=1;i<=q;i++)a[i]=lower_bound(lsh+1,lsh+len+1,a[i])-lsh;
	for(int i=1;i<=q;i++){
		ll x=a[i];
		if(s.find(x)==s.end()){
			s.insert(x);
			p=x,ww=1;updata(1,1,len);
			p=x;int rnk=query(1,1,len);
			ll val=kthsum(1,1,len,rnk-1);
			pii t=split(rt,rnk-1);
			int xx=t.fi,y=t.se,z=create(val+lsh[x]);
			upd(y,lsh[x]);
			rt=merge(xx,merge(z,y));
			++n;ss+=lsh[x];
		}
		else{
			s.erase(x);
			p=x,ww=-1;updata(1,1,len);
			p=x;int rnk=query(1,1,len);
			ll val=kthsum(1,1,len,rnk-1);
			pii t=split(rt,rnk-1);
			int xx=t.fi,y=t.se,z;
			t=split(y,1);
			y=t.fi,z=t.se;
			upd(z,-lsh[x]);
			rt=merge(xx,z);
			--n;ss-=lsh[x];
		}
		if(n<=1){puts("0");continue;}
		
		int l=1,r=(n+1)/2,res=0;
		while(l<=r){
			int mid=l+r>>1;
			if(kthsum(1,1,len,mid)>=ss-kthsum(1,1,len,n-mid+1))l=mid+1,res=mid;
			else r=mid-1;
		}
		// cout<<res<<"\n";
		pii t=split(rt,res-1);
		int xx=t.fi,y=t.se;
		lll ans=(2*res)*ss;
		ans-=2*sum[xx];
		// cout<<xx<<" "<<y<<" "<<sum[xx]<<" "<<sum[y]<<"\n";
		rt=merge(xx,y);
		t=split(rt,n-res);
		xx=t.fi,y=t.se;
		ans-=2*sum[y];
		rt=merge(xx,y);
		if(res<=n-res)ans+=ss-2*kthsum(1,1,len,res);
		write(ans),puts("");
	}
}

bool med;
int T;
signed main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	
	// cerr<<(&mbe-&med)/1024.0/1024.0<<"\n";
	
	T=1;
	while(T--)work();
}